################################################################################
# PowerShell OnTAP Library
# License: http://www.codeplex.com/PowerShellOnTAP/license
################################################################################
###
### PowerShell OnTAP Documentation:
###
###   Getting started, first thing you will need to do is create a [NaServer] object like so:
###     $filer = New-NaServer -server "TOASTER" -credentials (Get-Credential)
###
###   Note: The default OnTAPI version is 1.0; use Get-NaSystemOnTAPIVersion to retrieve the version of API the server supports.
###
################################################################################
$PowerShellOnTAP = $MyInvocation.MyCommand.Path
$NaOnTAPIService = "/servlets/netapp.servlets.admin.XMLrequest_filer"
$NaOnTAPEncoding = [System.Text.Encoding]::Utf8
$NaOnTAPDTD      = "file:/etc/netapp_filer.dtd"
$NaOnTAPXMLNS    = "http://www.netapp.com/filer/admin"

################################################################################
### ----------------------------------------------------------------------------
### Get-NaHelp
###   Displays the help documentation for the PowerShell OnTAP library.
###
###   Example: 
###            Get-NaHelp
###
################################################################################
function Get-NaHelp {
    gc $PowerShellOnTAP |? { $_ -match "^###( |$)" } |% { $_ -replace "^### ?","" } | more
}

################################################################################
### ----------------------------------------------------------------------------
### New-NaServer -server [string] -credentials [PSCredential] [-vfiler [string]] [-secure] [-version [string]]
###   Creates a new [NaServer] object used to call OnTAPI.
###
###   Example: 
###            $server = New-NaServer -server "TOASTER" -credentials (Get-Credential) -secure
###
################################################################################
function New-NaServer {
    param (
        [string]                                    $server      = $(throw "The parameter -server is required."),
        [System.Management.Automation.PSCredential] $credentials = $(throw "The parameter -credentials is required."),
        [string]                                    $vfiler,
        [switch]                                    $secure      = $false,
        [string]                                    $version     = "1.0"
    )
    
    return New-NaObject -properties @{
        Server      = $server;
        vFiler      = $vfiler;
        Secure      = $secure;
        Credentials = $credentials;
        Version     = $version;
    }
}

################################################################################
### ----------------------------------------------------------------------------
### New-NaRequest -name [string]
###   Creates a new [NaRequest] object representing an OnTAP API.
###
###   Example: 
###            $request = New-NaResult -name "system-get-version"
###
################################################################################
function New-NaRequest {
    param (
        [string] $name = $(throw "The parameter -name is required.")
    )
    
    $ErrorActionPreference = "Stop"

    return New-NaObject -properties @{
        Name       = $name;
        Parameters = @()
    } -methods @{
        ToXml = {
            if ([int]$this.Parameters.Count -eq 0) {
                $xml = ("<{0}/>" -f $this.Name)
            } else {
                $xml = ("<{0}>" -f $this.Name)
                $this.Parameters |% { $xml += $_.ToXml() }                
                $xml += ("</{0}>" -f $this.Name)
            }
            
            return $xml
        }
    }
}

################################################################################
### ----------------------------------------------------------------------------
### New-NaRequestParameter -name [string] -value [object]
###   Creates a new [NaRequestParameter] to include with a [NaRequest] API object.
###
###   Example: 
###            $request = New-NaResult -name "quota-off"
###            $request.Parameters += New-NaRequestParameter -name "volume" -value "vol0"
###
################################################################################
function New-NaRequestParameter {
    param (
        [string] $name  = $(throw "The parameter -name is required."),
        [object] $value = $(throw "The parameter -value is required.")
    )
    
    $ErrorActionPreference = "Stop"

    return New-NaObject -properties @{
        Name     = $name;
        Value    = $value;
    } -methods @{
        ToXml = {
            return ("<{0}>{1}</{0}>" -f $this.Name,$this.Value)
        }
    }
}

################################################################################
### ----------------------------------------------------------------------------
### Get-NaResult -server [NaServer] -request [NaRequest]
###   Retrieves the XML result of an OnTAP API request.
###
###   Example: 
###            $server  = New-NaServer -name "TOASTER" -credentials (Get-Credential) -secure
###            $request = New-NaRequest -name "system-get-version"
###            $result  = Get-NaResult -server $server -request $request
###
################################################################################
function Get-NaResult {
    param (
        [PSObject] $server  = $(throw "The parameter -server is required."),
        [PSObject] $request = $(throw "The parameter -request is required.")
    )
    
	$ErrorActionPreference = "Stop"
    
    if ($server.Secure) {
	    $url = "https://{0}{1}" -f ($server.Server,$NaOnTAPIService)
	} else {
	    $url = "http://{0}{1}" -f ($server.Server,$NaOnTAPIService)
	}
	
	$requestXml = "<?xml version=""1.0"" encoding=""utf-8"" ?><!DOCTYPE netapp SYSTEM ""{0}""><netapp {1}version=""{2}"" xmlns=""{3}"">{4}</netapp>" -f (
                    $NaOnTAPDTD,
                    $(if (![string]::IsNullOrEmpty($server.vFiler)) { "vfiler=""$($server.vFiler) """ }),
                    $server.Version,
                    $NaOnTAPXMLNS,
                    $request.ToXml()
                )
    
	$response = Invoke-NaApi -url $url -method "POST" -content $requestXml -credentials ($server.Credentials) -encoding $NaOnTAPEncoding	
	$result   = ConvertTo-NaResult $response
	
	return $result
}

################################################################################
### ----------------------------------------------------------------------------
### Test-NaApi -server [NaServer] -api [string] [-parameters [Hashtable]]
###   Returns the raw XML of an OnTAP API request.
###
###   Example:
###            $server = New-NaServer -name "TOASTER" -credentials (Get-Credential) -secure
###            Test-NaApi -server $server -api "snapmirror-get-volume-status" -parameters @{ volume = "vol0" }
###
################################################################################
function Test-NaApi {
    param (
        [PSObject]  $server      = $(throw "The parameter -server is required."),
        [string]    $api         = $(throw "The parameter -api is required."),
        [Hashtable] $parameters
    )
    
    $ErrorActionPreference = "Stop"

    $request = New-NaRequest -name $api
    
    if ([int]$parameters.Count -gt 0) {
        $parameters.Keys |% { $request.Parameters += New-NaRequestParameter -name $_ -value $parameters[$_] }
    }
    
    $result  = Get-NaResult -server $server -request $request
    
    return Format-NaXml -xml $result
}

################################################################################
### ----------------------------------------------------------------------------
### Test-NaResult -result [NaResult]
###   Returns true if the status property is "passed", otherwise false.
###
###   Example: 
###            $server  = New-NaServer -name "TOASTER" -credentials (Get-Credential) -secure
###            $request = New-NaRequest -name "system-get-version"
###            $result  = Get-NaResult -server $server -request $request
###            
###            if (!(Test-NaResult -result $result)) {
###              throw ("Failed to retrieve the system version; NaError {1}: {2}" -f "vol0",$result.errno,$result.reason)
###            }
###
################################################################################
function Test-NaResult {
    param (
        [System.Xml.XmlNode] $result = $(throw "The parameter -result is required.")
    )
    
    $ErrorActionPreference = "Stop"

    return ($result.status -eq "passed");
}

################################################################################
### ----------------------------------------------------------------------------
### Throw-NaResultError -result [NaResult]
###   Throws a NaResultError exception.
###
###   Example: 
###            $server  = New-NaServer -name "TOASTER" -credentials (Get-Credential) -secure
###            $request = New-NaRequest -name "quota-off"
###            $request.Parameters += New-NaRequestParameter -name "volume" -value "vol0"
###            $result  = Get-NaResult -server $server -request $request
###            
###            if (!(Test-NaResult -result $result)) {
###              Throw-NaResultError $result
###            }
###
################################################################################
function Throw-NaResultError {
    param (
        [System.Xml.XmlNode] $result = $(throw "The parameter -result is required.")
    )
    
    throw ("NaError[{0}]: {1}" -f [NaError]$result.errno,$result.reason)
}

################################################################################
### ----------------------------------------------------------------------------
### Test-NaApiVersion -server [NaServer] -version [string]
###   Returns true is the server version is at least the specified version, otherwise false.
###
###   Example: 
###            $server = New-NaServer -name "TOASTER" -credentials (Get-Credential) -version "1.8"
###
###            if (!(Test-NaApiVersion -server $server -version "1.6")) {
###              throw ("The server API version {0} does not support this command." -f $server.Version)
###            }
################################################################################
function Test-NaApiVersion {
    param (
        [PSObject] $server  = $(throw "The parameter -server is required."),
        [string]   $version = $(throw "The parameter -version is required.")
    )
    
    return ([Decimal]$server.Version -ge [Decimal]$version)
}

################################################################################
### ----------------------------------------------------------------------------
### New-NaObject [-properties [Hashtable]] [-methods [Hashtable]]
###   Creates a new [NaObject] object.
###
###   Example: 
###            $person = New-NaObject -properties @{ Name = "Toaster" } -methods @{ ToString = { return $this.Name } }
###            $person.ToString()
###            $person.Name = "Freezer"
###            $person.ToString()
###
################################################################################
function New-NaObject {
    param (
        [Hashtable] $properties,
        [Hashtable] $methods
    )
    
    $ErrorActionPreference = "Stop"

    $object = New-Object PSObject
    
    if ($properties -ne $null -and $properties.Count -gt 0) {
        foreach ($key in $properties.Keys) {
            $object = Add-Member -inputObject $object -memberType NoteProperty -name $key -value ($properties[$key]) -passThru
        }
    }
    
    if ($methods -ne $null -and $methods.Count -gt 0) {
        foreach ($key in $methods.Keys) {
            $object = Add-Member -inputObject $object -memberType ScriptMethod -name $key -value ($methods[$key]) -passThru
        }
    }
    
    return $object
}

################################################################################
### ----------------------------------------------------------------------------
### New-NaEnum -name [string] -values [string[]]
###   Creates a new [NaEnum] enumeration class.
###
###   Example:
###            New-NaEnum -name "NaColor" -values @("Red", "Blue")
###            $red = [NaColor]::Red
###            $blue = [NaColor]::Blue
###
################################################################################
function New-NaEnum {
    param (
        [string]    $name   = $(throw "The parameter -name is required."),
        [Hashtable] $values = $(throw "The parameter -values is required.")
    )
    
    $ErrorActionPreference = "Stop"

    $domain        = [System.Threading.Thread]::GetDomain()
    $assembly      = New-Object System.Reflection.AssemblyName
    $assembly.Name = "NetApp.Management" 

    $assemblyBuilder = $domain.DefineDynamicAssembly($assembly, [System.Reflection.Emit.AssemblyBuilderAccess]::Save -bor [System.Reflection.Emit.AssemblyBuilderAccess]::Run)
    $moduleBuilder   = $assemblyBuilder.DefineDynamicModule("DynamicModule", "DynamicModule.mod");
    $enumBuilder     = $moduleBuilder.DefineEnum($name, [System.Reflection.TypeAttributes]::Public, [System.Int32]);

    foreach ($key in $values.Keys) {
        $enumBuilder.DefineLiteral($key, $values[$key]) | Out-Null
    }

    $enumBuilder.CreateType() | Out-Null;
}

################################################################################
### ----------------------------------------------------------------------------
### Invoke-NaApi -url [string] -method [string] -content [string] -encoding [System.Text.Encoding] -credentials [PSCredential]
###   Retrieves the content from an HTTP[S] request.
###
###   Example: 
###            $response = Invoke-NaApi -url "http://toaster/filer/admin" -method "GET" -credentials (Get-Credential)
###
################################################################################
function Invoke-NaApi {
    param (
        [string]                                    $url         = $(throw "The parmaeter -url is required."),
        [string]                                    $method,
        [string]                                    $content,
        [System.Text.Encoding]                      $encoding    = [System.Text.Encoding]::Default,
        [System.Management.Automation.PSCredential] $credentials
    )
    
    $ErrorActionPreference = "Stop"

    $request = [System.Net.WebRequest]::Create($url)
    
    if (![string]::IsNullOrEmpty($method)) {
        $request.Method = $method
    }
    
    if ($credentials -ne $null) {
        $request.Credentials = $credentials.GetNetworkCredential()
    }
    
    if (![string]::IsNullOrEmpty($content)) {
        $buffer = $encoding.GetBytes($content)
        $stream = $request.GetRequestStream()
        $stream.Write($buffer, 0, $buffer.Length)
        $stream.Close()
    }
    
    $headers  = @{}
    $content  = $null
    $response = $request.GetResponse()
    
    foreach ($key in $response.Headers.Keys) {
        $headers[$key] = $response.Headers[$key]
    }
    
    if ($response.StatusCode -ne "OK") {
        throw "NaError: Invalid HTTP status code returned by the OnTAP service API; expected 200 OK, received $([int]$response.StatusCode) $($response.StatusDescription)."
    }

    $reader = New-Object System.IO.StreamReader ($response.GetResponseStream(),$encoding)
    $content = $reader.ReadToEnd()
    $reader.Close()
    
    $response.Close()
    
    return $content
}

################################################################################
### ----------------------------------------------------------------------------
### Format-NaXml -xml [System.Xml.XmlNode] [-indent [int]]
###   Formats the XML node into a pretty XML string.
###
###   Example: 
###            $xml = [xml]"<netapp version=""1.0""><system-get-version /></netapp>"
###            Format-NaXml -xml $xml
###
################################################################################
function Format-NaXml { 
    param (
        [System.Xml.XmlNode] $xml    = $(throw "The parameter -xml is required."),
        [int]                $indent = 2
    )
    
    $ErrorActionPreference = "Stop"

    $sw = New-Object System.IO.StringWriter 
    $xw = New-Object System.XMl.XmlTextWriter $sw    
    $xw.Formatting = "indented" 
    $xw.Indentation = $indent    
    $xml.WriteTo($xw)     
    $xw.Flush() 
    $sw.Flush()
    
    return $sw.ToString() 
}

################################################################################
### ----------------------------------------------------------------------------
### ConvertTo-NaResult -inputObject [string]
###   Converts raw XML into a [NaResult] XML node.
###
###   Example: 
###            $server   = New-NaServer -name "TOASTER" -credentials (Get-Credential) -secure
###            $response = Test-NaApi -server $server -api "system-get-version"
###            $result   = ConvertTo-NaResult -inputObject $response
###            echo $result.version
###
################################################################################
function ConvertTo-NaResult {
    param (
        [string] $inputObject = $(throw "The parameter -inputObject is required.")
    )
    
    $ErrorActionPreference = "Stop"

    $xml = New-Object Xml
    $xml.psbase.XmlResolver = $null
    $xml.LoadXml($inputObject)
    
    return $xml.netapp[1].results
}

################################################################################
### ----------------------------------------------------------------------------
### [NaError]
###   Enumerated type of all OnTAPI error codes.
###
###   Example: [NaError]::EONTAPI_ENAMETOOLONG
################################################################################
$NaError = New-NaEnum -name "NaError" -values @{
    ONTAPI_EPERM = 1;
    ONTAPI_ENOENT = 2;
    ONTAPI_ESRCH = 3;
    ONTAPI_EINTR = 4;
    ONTAPI_EIO = 5;
    ONTAPI_ENXIO = 6;
    ONTAPI_E2BIG = 7;
    ONTAPI_ENOEXEC = 8;
    ONTAPI_EBADF = 9;
    ONTAPI_ECHILD = 10;
    ONTAPI_EDEADLK = 11;
    ONTAPI_ENOMEM = 12;
    ONTAPI_EACCES = 13;
    ONTAPI_EFAULT = 14;
    ONTAPI_ENOTBLK = 15;
    ONTAPI_EBUSY = 16;
    ONTAPI_EEXIST = 17;
    ONTAPI_EXDEV = 18;
    ONTAPI_ENODEV = 19;
    ONTAPI_ENOTDIR = 20;
    ONTAPI_EISDIR = 21;
    ONTAPI_EINVAL = 22;
    ONTAPI_ENFILE = 23;
    ONTAPI_EMFILE = 24;
    ONTAPI_ENOTTY = 25;
    ONTAPI_ETXTBSY = 26;
    ONTAPI_EFBIG = 27;
    ONTAPI_ENOSPC = 28;
    ONTAPI_ESPIPE = 29;
    ONTAPI_EROFS = 30;
    ONTAPI_EMLINK = 31;
    ONTAPI_EPIPE = 32;
    ONTAPI_EDOM = 33;
    ONTAPI_ERANGE = 34;
    ONTAPI_EAGAIN = 35;
    ONTAPI_EINPROGESS = 36;
    ONTAPI_EALREADY = 37;
    ONTAPI_ENOTSOCK = 38;
    ONTAPI_EDESTADDRREQ = 39;
    ONTAPI_EMSGSIZE = 40;
    ONTAPI_EPROTOTYPE = 41;
    ONTAPI_ENOPROTOOPT = 42;
    ONTAPI_EPROTONOSUPPORT = 43;
    ONTAPI_ESOCKTNOSUPPORT = 44;
    ONTAPI_EOPNOTSUPP = 45;
    ONTAPI_EPFNOSUPPORT = 46;
    ONTAPI_EAFNOSUPPORT = 47;
    ONTAPI_EADDRINUSE = 48;
    ONTAPI_EADDRNOTAVAIL = 49;
    ONTAPI_ENETDOWN = 50;
    ONTAPI_ENETUNREACH = 51;
    ONTAPI_ENETRESET = 52;
    ONTAPI_ECONNABORTED = 53;
    ONTAPI_ECONNRESET = 54;
    ONTAPI_ENOBUFS = 55;
    ONTAPI_EISCONN = 56;
    ONTAPI_ENOTCONN = 57;
    ONTAPI_ESHUTDOWN = 58;
    ONTAPI_ETOOMANYREFS = 59;
    ONTAPI_ETIMEDOUT = 60;
    ONTAPI_ECONNREFUSED = 61;
    ONTAPI_ELOOP = 62;
    ONTAPI_ENAMETOOLONG = 63;
    ONTAPI_EHOSTDOWN = 64;
    ONTAPI_EHOSTUNREACH = 65;
    ONTAPI_ENOTEMPTY = 66;
    ONTAPI_EPROCLIM = 67;
    ONTAPI_EUSERS = 68;
    ONTAPI_EDQUOT = 69;
    ONTAPI_ESTALE = 70;
    ONTAPI_EREMOTE = 71;
    ONTAPI_EBADRPC = 72;
    ONTAPI_ERPCMSGDENIED = 73;
    ONTAPI_EPROGUNAVAIL = 74;
    ONTAPI_EPROGMISMATCH = 75;
    ONTAPI_EPROCUNAVAIL = 76;
    ONTAPI_ENOLCK = 77;
    ONTAPI_ENOSYS = 78;
    ONTAPI_EFTYPE = 79;
    ONTAPI_EMTUTOOBIG = 80;
    ONTAPI_EOFFLINE = 81;
    ONTAPI_EBADSTREAM = 82;
    ONTAPI_EBADSTREAMDIR = 83;
    ONTAPI_ELOADCOMPLETE = 84;
    ONTAPI_EMOUNTING = 85;
    ONTAPI_EWFLUSH = 99;
    ONTAPI_EBADPATH = 100;
    ONTAPI_EBADCHAR = 101;
    ONTAPI_ESHARECONFLICT = 102;
    ONTAPI_ELOCKCONFLICT = 103;
    ONTAPI_ENOTCOVERED = 104;
    ONTAPI_EBADXINODE = 105;
    ONTAPI_ENOTXINODE = 106;
    ONTAPI_EBADOWNER = 107;
    ONTAPI_ERMTWRITELEN = 108;
    ONTAPI_EBADRMT = 109;
    ONTAPI_EKNOWNBADRMT = 110;
    ONTAPI_ERMTEOF = 111;
    ONTAPI_EDELPENDING = 112;
    ONTAPI_ETRUNCATED = 113;
    ONTAPI_EREJECTED = 114;
    ONTAPI_EREADONLY = 115;
    ONTAPI_EPARTNERREJECT = 116;
    ONTAPI_ETOOCOMPLEX = 117;
    ONTAPI_EREGX = 118;
    ONTAPI_EREGXBADVALUE = 119;
    ONTAPI_EPERSISTENCE = 120;
    ONTAPI_ESTHREAD = 121;
    ONTAPI_EDISABLED = 122;
    ONTAPI_ENOTVSCANNED = 123;
    ONTAPI_EFABRIC = 124;
    ONTAPI_ESYSTEMERR = 125;
    ONTAPI_EGSSAPI = 126;
    ONTAPI_ERPCGSSSEQNUM = 127;
    ONTAPI_EPROXYME = 128;
    ONTAPI_ERSRVCONFLICT = 129;
    ONTAPI_ERSRVNSUPPORTED = 130;
    ONTAPI_ENOQTREE = 131;
    ONTAPI_ENOTLOCKED = 132;
    ONTAPI_ELOCKCANCELLED = 133;
    ONTAPI_ENOSPCSNAP = 134;
    ONTAPI_ENOMORESNAPS = 135;
    ONTAPI_ERECURSE = 136;
    ONTAPI_ERECLAIM = 137;
    ONTAPI_EZEROLENREC = 138;
    ONTAPI_ENOTFSCREENED = 139;
    ONTAPI_EISVDISK = 140;
    ONTAPI_EWAFLMSGABORTED = 141;
    ONTAPI_EMSGNULLIFY = 142;
    ONTAPI_ECOMPRESSCHECK = 143;
    ONTAPI_EVOLSMALL = 144;
    ONTAPI_EVOLBIG = 145;
    ONTAPI_EVOLPAIRED = 146;
    ONTAPI_EVOLNOTFLEX = 147;
    ONTAPI_EVOLSTALE = 148;
    ONTAPI_ENOREG = 149;
    ONTAPI_ENOREGKEY = 150;
    ONTAPI_ECANNOTDELETE = 151;
    ONTAPI_EWORMNOCLOCK = 152;
    ONTAPI_EWORMVOLWORM = 153;
    ONTAPI_EWORMVOLSLC = 154;
    ONTAPI_EWORMVOLNOTWORM = 155;
    ONTAPI_EWORMSNAPLOCKED = 156;
    ONTAPI_EWORMSNAPRENAME = 157;
    ONTAPI_EWORMPERIOD = 158;
    ONTAPI_ENOSPCAGGR = 159;
    ONTAPI_EVOLOPNOTSUPP = 160;
    VDISK_ERROR_NOT_IMPLEMENTED = 9000;
    VDISK_ERROR_NOT_QTREE_ROOT = 9001;
    VDISK_ERROR_NOT_VDISK_TYPE = 9002;
    VDISK_ERROR_NO_SUCH_INITGROUP = 9003;
    VDISK_ERROR_INITGROUP_EXISTS = 9004;
    VDISK_ERROR_NOT_VALID_FC_WWN = 9005;
    VDISK_ERROR_NOT_VALID_ISCSI_NAME = 9006;
    VDISK_ERROR_NODE_NOT_IN_INITGROUP = 9007;
    VDISK_ERROR_INITGROUP_HAS_NODE = 9008;
    VDISK_ERROR_LUN_MAPPING_CONFLICT = 9009;
    VDISK_ERROR_INITGROUP_WRONG_TYPE = 9010;
    VDISK_ERROR_NO_SUCH_ATTRIBUTE = 9011;
    VDISK_ERROR_VDISK_EXISTS = 9012;
    VDISK_ERROR_VDISK_EXPORTED = 9013;
    VDISK_ERROR_VDISK_NOT_ENABLED = 9014;
    VDISK_ERROR_VDISK_NOT_DISABLED = 9015;
    VDISK_ERROR_NO_SUCH_LUNMAP = 9016;
    VDISK_ERROR_NO_SUCH_VDISK = 9017;
    VDISK_ERROR_NOT_IN_SAME_QTREE = 9018;
    VDISK_ERROR_SOURCE_IS_VDISK = 9019;
    VDISK_ERROR_NO_SUCH_DIRECTORY = 9020;
    VDISK_ERROR_INVALID_SNAPSHOT_PATH = 9021;
    VDISK_ERROR_NOT_IN_SAME_VOLUME = 9022;
    VDISK_ERROR_INITGROUP_HAS_VDISK = 9023;
    VDISK_ERROR_INITGROUP_HAS_LUN = 9024;
    VDISK_ERROR_INITGROUP_MISSING_ARGS = 9025;
    VDISK_ERROR_INITGROUP_INVALID_ATTR_TYPE = 9026;
    VDISK_ERROR_INITGROUP_INVALID_ATTR_VALUE = 9027;
    VDISK_ERROR_NO_EXPORTED_VDISK_SHARE_WRITE = 9028;
    VDISK_ERROR_INITGROUP_MAPS_EXIST = 9029;
    VDISK_ERROR_VOLUME_NOT_SPACE_RESERVED = 9030;
    VDISK_ERROR_SNAPSHOT_FILE_NOT_VDISK = 9031;
    VDISK_ERROR_NITGROUP_INVALID_ATTR_VALUE_OS_TYPE = 9032;
    VDISK_ERROR_MUST_SPECIFY_F_FLAG = 9033;
    VDISK_ERROR_SIZE_TOO_LARGE = 9034;
    VDISK_ERROR_RESIZE_TOO_LARGE = 9035;
    VDISK_ERROR_NO_SUCH_VOLUME = 9036;
    VDISK_ERROR_USER_ABORT_ACTION = 9037;
    VDISK_ERROR_CLONING = 9038;
    VDISK_ERROR_INITIATOR_HAS_VDISK = 9039;
    VDISK_ERROR_FILE_IS_SPC_RESERVED = 9040;
    VDISK_ERROR_SIZE_TOO_SMALL = 9041;
    VDISK_ERROR_SIZE_UNCHANGED = 9042;
    VDISK_ERROR_NO_SUCH_SNAPSHOT = 9043;
    VDISK_ERROR_IGROUP_NOT_THROTTLED = 9044;
    VDISK_ERROR_IGROUP_ALREDY_THROTTLED = 9045;
    VDISK_ERROR_THROTTLE_TOO_MUHC = 9046;
    VDISK_ERROR_THROTTLE_BEING_DELETED = 9047;
    VDISK_ERROR_NO_SUCH_CLONE = 9048;
    VDISK_ERROR_NO_ISCSI_THROTTLES = 9049;
    VDISK_ERROR_INVALID_ATTR_MODE_VALUE = 9050;
    VDISK_ERROR_INITGROUP_MEMBER_CONFLICTING_OS_TYPES = 9051;
    VDISK_ERROR_INITGROUP_SET_TYPE_CONFLICT = 9052;
    VDISK_ERROR_INITGROUP_MEMBER_VSA_MIXED = 9053;
    VDISK_ERROR_INITGROUP_SET_VSA_CONFLICT = 9054;
    VDISK_ERROR_RESIZE_FIXES_NOT_GEOM_ALIGNED = 9055;
    VDISK_ERROR_RESIZE_VLD_TYPE_LUN_FIXES = 9056;
    VDISK_ERROR_RESIZE_IMGAG_TYPE_LUN_FIXES = 9057;
    VDISK_ERROR_INITGROUP_F_FLAG_REQUIRED = 9058;
    VDISK_ERROR_USE_PARTNER_NOT_APPLICABLE = 9059;
    VDISK_ERROR_RESTORE_WALKOVER_EACHOTHER = 9060;
    VDISK_ERROR_VOLUME_SPARSE = 9061;
    VDISK_ERROR_DESTROY_LUN_BUSY = 9062;
    VDISK_ERROR_CANT_CREATE_INITGROUP_FILE = 9063;
    VDISK_ERROR_CANT_WRITE_INITGROUP_FILE = 9064;
    VDISK_ERROR_CANT_RENAME_INITGROUP_FILE = 9065;
    VDISK_ERROR_CANT_CREATE_VFILER_SHADOW_INITGROUP_FILE = 9066;
    VDISK_ERROR_CANT_WRITE_VFILER_SHADOW_INITGROUP_FILE = 9067;
    VDISK_ERROR_CANT_RENAME_VFILER_SHADOW_INITGROUP_FILE = 9068;
    VDISK_ERROR_INITGROUP_TOO_MANY_NODENAMES = 9069;
    VDISK_ERROR_LUN_MISSING_FROM_SNAPSHOT = 9070;
    VDISK_ERROR_SNAPVALIDATOR_ERROR = 9071;
    VDISK_ERROR_PARTNER_HAS_LUN = 9072;
    VDISK_ERROR_PARTNER_NOT_REACHABLE = 9073;
    VDISK_ERROR_PORTSET_NO_SUCH_SET = 9074;
    VDISK_ERROR_PORTSET_ALREADY_EXIST = 9075;
    VDISK_ERROR_PORTSET_HAS_PORT = 9076;
    VDISK_ERROR_PORTSET_INVALID_PORT_NAME = 9077;
    VDISK_ERROR_PORTSET_TOO_MANY_PORTS = 9078;
    VDISK_ERROR_PORTSET_WRONG_TYPE = 9079;
    VDISK_ERROR_INITGROUP_ALREADY_BOUND = 9080;
    VDISK_ERROR_INITGROUP_NOT_BOUND = 9081;
    VDISK_ERROR_INITGROUP_EMPTY_PSET_BIND = 9082;
    VDISK_ERROR_PORTSET_NO_SUCH_PORT = 9083;
    VDISK_ERROR_PORTSET_NO_SUCH_FILER_NAME = 9084;
    VDISK_ERROR_PARTNER_HAS_DIFFERENT_OS_TYPE = 9085;
    VDISK_ERROR_PARTNER_HAS_DIFFERENT_VSA_SETTING = 9086;
    VDISK_ERROR_PORTSET_CANT_CREATE_FILE = 9087;
    VDISK_ERROR_PORTSET_CANT_WRITE_FILE = 9088;
    VDISK_ERROR_PORTSET_CANT_READ_FILE = 9089;
    VDISK_ERROR_PORTSET_CANT_OPEN_FILE = 9090;
    VDISK_ERROR_LUN_TOO_LARGE = 9091;
    VDISK_ERROR_PORTSET_IC_DOWN = 9092;
    VDISK_ERROR_CLONE_NOT_SPLITTING = 9093;
    VDISK_ERROR_LUN_HAS_NO_SERIAL_NO = 9095;
    VDISK_ERROR_PORTSET_THROTTLE_EXCEEDED = 9096;
    VDISK_ERROR_PORTSET_CANT_DESTROY_BOUND_PORTSET = 9097;
    VDISK_ERROR_CFMODE_MISMATCH = 9098;
    VDISK_ERROR_PORTSET_NOT_VALID_CFMODE = 9099;
    VDISK_ERROR_CANNOT_CHANGE_SPCRES_DURING_SPLIT = 9100;
    VDISK_ERROR_INITGROUP_BIND_WRONG_TYPE = 9101;
    VDISK_ERROR_DB_BAD_INDEX = 9102;
    VDISK_ERROR_DB_NO_SUCH_DATABASE = 9103;
    VDISK_ERROR_ALUA_NOT_SUPPORTED_ON_ISCSI = 9104;
    VDISK_ERROR_ALUA_NOT_SUPPORTED_ON_CFMODE = 9105;
    APIERROR = 13001;
    APIAUTHENTICATION = 13002;
    APIPRIVILEGE = 13003;
    APIPRIVILEDGE = 13003;
    APIEXCEPTION = 13004;
    APINOTFOUND = 13005;
    APIMISSINGARGUMENT = 13006;
    APINOTIMPLEMENTED = 13007;
    APILICENSE = 13008;
    APIINDEXTOOLARGE = 13009;
    APIUNSUPPORTEDVERSION = 13010;
    APITRANSMISSION = 13011;
    OPNOTSUPPORTED = 13012;
    ALREADYSTARTED = 13013;
    NOTSTARTED = 13014;
    SERVICENOTSTOPPED = 13015;
    NOTWHILEWAITINGFORGIVEBACK = 13016;
    NOTINMAINTMODE = 13017;
    NOTINREADONLYMODE = 13018;
    APITOOMANYENTRIES = 13019;
    SNAPSHOTEXISTS = 13020;
    SNAPSHOTDOESNOTEXIST = 13021;
    SNAPSHOTTOOMANY = 13022;
    SNAPSHOTNOTALLOWED = 13023;
    SNAPSHOTBUSY = 13024;
    SNAPSHOTNOSPACE = 13025;
    DUPLICATEDSID = 13026;
    INVALIDDSID = 13027;
    INVALIDMSID = 13028;
    AMBIGUOUS_DSID = 13029;
    VOLUMESNAPRESTOREERROR = 13038;
    VOLUMEQUIESCED = 13039;
    VOLUMEDOESNOTEXIST = 13040;
    VOLUMEMOUNTING = 13041;
    VOLUMEOFFLINE = 13042;
    VOLUMEREADONLY = 13043;
    VOLUMENAMEINVALID = 13044;
    VOLUMERGSIZEINVALID = 13045;
    VOLUMELANGUAGEINVALID = 13046;
    VOLUMEDISKSIZEINVALID = 13047;
    VOLUMEDISKDUP = 13048;
    VOLUMERGINVALID = 13049;
    QUOTAPARSEERROR = 13050;
    QUOTAINVALID = 13051;
    QUOTAEXISTS = 13052;
    QUOTADOESNOTEXIST = 13053;
    QUOTADIRECTIVE = 13054;
    API_CONNECTION = 13055;
    API_CONNECTION_DROPPED = 13056;
    API_RECEPTION = 13057;
    VOL_NOT_OFFLINE = 13058;
    VOL_NOT_RESTRICTED = 13059;
    VOL_ONLINE = 13060;
    VOL_RESTRICTED = 13061;
    VOL_SPACE_FOR_GUARANTEE = 13062;
    VOL_TOO_MANY = 13063;
    VFILEROPNOTALLOWED = 13070;
    VFILERNOTFOUND = 13071;
    VFILEROPNOTCOMPLETED = 13072;
    IPSPACENOTFOUND = 13073;
    QTREEEXISTS = 13080;
    QTREENOTOWNER = 13081;
    QTREEMAX = 13082;
    CMSINVALIDREQUEST = 13090;
    CMSNOTENABLED = 13091;
    CMSPROCESSINGERROR = 13092;
    SNAPMIRROROFF = 13100;
    SNAPMIRRORPARSERERROR = 13101;
    SNAPMIRRORERROR = 13102;
    ISCSISECINVALIDAUTHTYPE = 13109;
    ISCSISECINVALIDINPUTERROR = 13110;
    ISCSISECPROCESSINGERROR = 13111;
    ISCSISECINITNOTFOUNDERROR = 13112;
    FILENOTFOUND = 13113;
    INTERNALERROR = 13114;
    INVALIDINPUTERROR = 13115;
    SETSPCRESERROR = 13116;
    ADAPTERNOTFOUND = 13122;
    ADAPTERPARTNER = 13123;
    ADAPTERINVALIDTYPE = 13125;
    NOADAPTERPARTNER = 13126;
    NOVIRTUALADAPTERS = 13127;
    NOTCLUSTERED = 13128;
    CLUSTERED = 13129;
    DISKNOTFOUND = 13150;
    SWAPINPROGRESS = 13151;
    NOTDISKOWNER = 13152;
    DISKINRAIDZEROVOL = 13153;
    DISKISSPARE = 13154;
    VOLUMEPLEXINVALID = 13155;
    VOLUMEINUSE = 13156;
    VOLUMENOTONLINE = 13157;
    VOLUMEBUSY = 13158;
    VOLUMECIFSTERMINATE = 13159;
    VOLUMECREATING = 13160;
    CLIENTSTATSVFILER = 13161;
    CLIENTSTATSNOTENABLED = 13162;
    NOACTIVECLIENTS = 13163;
    CIFSNOTCONFIGURED = 13164;
    DNSNOTENABLED = 13165;
    HOSTNOTFOUND = 13166;
    LDAPSVRNOTFOUND = 13167;
    SVCDISABLED = 13200;
    SVCNOTAVAIL = 13201;
    SHAREACCESSDENIED = 13202;
    SHAREEXISTS = 13203;
    SHARETOOMANY = 13204;
    CIFSSHARINGVIOLATION = 13210;
    SANOWNNOTENABLED = 13210;
    INVALIDHOST = 13211;
    INVALIDOWNERID = 13212;
    INVALIDOWNER = 13213;
    INVALIDPASSWORD = 13214;
    EXPORTSINCOMPATIBLE = 13215;
    INODENUMBERTOOSMALL = 13216;
    INODENUMBERTOOLARGE = 13217;
    INVALIDINODE = 13218;
    INELIGIBLEINODE = 13219;
    PARENTINFONOTLOADED = 13220;
    I2PNOTENABLED = 13221;
    VV_COMMON = 13222;
    CIFS_LOGIN_FAILED = 13250;
    CIFS_BIND_FAILED = 13251;
    CIFS_DNS_REQUIRED = 13252;
    CIFS_KRB_CONFLICT = 13253;
    CIFS_AD_CLOCK_SKEW = 13254;
    CIFS_AD_RESET_REQUIRED = 13255;
    CIFS_LIST_UNAVAILABLE = 13256;
    CIFS_DC_CONNECT_FAILED = 13257;
    CIFS_HAVE_SESSION_SCOPED_LOCKS = 13258;
    CIFS_PASSWD_AND_GROUP_REQUIRED = 13259;
    CIFS_SETUP_CANNOT_WRITE = 13260;
    EMS_INVOKE_FAILED = 13301;
    EMS_INVOKE_BAD_PARAM = 13303;
    EMS_INVOKE_ID_BAD = 13310;
    EMS_INVOKE_SEVERITY_REQUIRED = 13311;
    EMS_INVOKE_SEVERITY_INVALID = 13312;
    EMS_INVOKE_SEVERITY_NOT_VARIABLE = 13313;
    EMS_INVOKE_PARAMS_INSUFFICIENT = 13314;
    EMS_INVOKE_VERSION_INVALID = 13315;
    EMS_INVOKE_SUPRESS_DUP = 13316;
    EMS_INVOKE_SUPRESS_TIMER = 13317;
    EMS_INVOKE_NVRAM_TOO_BIG = 13318;
    EMS_INVOKE_QUEUE_FULL = 13319;
    REALLOCATE_EXISTS = 13501;
    REALLOCATE_BADPATH = 13502;
    REALLOCATE_NOMEM = 13503;
    REALLOCATE_NOSCAN = 13504;
    REALLOCATE_BADVOL = 13505;
    REALLOCATE_READONLY = 13506;
    REALLOCATE_BADSCHED = 13507;
    REALLOCATE_OFF = 13508;
    REALLOCATE_SNAPSHOT = 13509;
    DISKNOTSPARE = 13510;
    DISKTOOSMALL = 13511;
    RAIDGROUPDEGRADED = 13512;
    SAVECOREDISK = 13513;
    INVALIDSTATE = 13514;
    CANT_USE_ALL_DISKS = 13515;
    NPMINVPLOC = 13600;
    NPMNOPKG = 13601;
    NPMNOMETA = 13602;
    NPMERXMETA = 13603;
    INCRCOPYFAILED = 13604;
    INCRCOPYOPNOTFOUND = 13605;
    INCRCOPYINVALIDUUID = 13606;
    INCRCOPYINVALIDOP = 13607;
    INCRCOPYNOMEM = 13608;
    INCRCOPYINVALIDINPUT = 13609;
    INCRCOPYINVALIDOPTYPE = 13610;
    INCRCOPYDUPLICATESESSION = 13611;
    INCRCOPYNOTSUPPORT = 13612;
    INCRCOPYVOLOFFLINE = 13613;
    INCRCOPYVOLNOTFOUND = 13614;
    INCRCOPYSNAPCREATIONFAIL = 13615;
    INCRCOPYSNAPSHOTEXIST = 13616;
    INCRCOPYNOSTREAMESTABLISHED = 13617;
    INCRCOPYAGAIN = 13618;
    INCRCOPY_CSM_CALL_FAIL = 13619;
    INCRCOPY_CSM_SEND_FAIL = 13620;
    INCRCOPY_CSM_CANT_GET_SESSION = 13621;
    INCRCOPY_CSM_CANT_REGISTER_SENDCB = 13622;
    DSIDPARSEERROR = 13623;
    INCRCOPY_SET_INCORE_QUIESCE_VOL_FAIL = 13624;
    INCRCOPY_UNSET_INCORE_QUIESCE_VOL_FAIL = 13625;
    INCRCOPY_SET_ONDISK_QUIESCE_VOL_FAIL = 13626;
    CGERROR = 13700;
    CGSNAPERR = 13701;
    CGOFF = 13702;
    CHARMAP_INVALID = 13800;
    CHARMAP_NO_PERSIST = 13801;
    TOERRMIN = 13900;
    SERVICENOTINITIALIZED = 13901;
    SERVICENOTLICENSED = 13902;
    SERVICENOTENABLED = 13903;
    MBOXDEGRADED = 13904;
    MBOXUNKNOWN = 13905;
    MBOXVERSIONMISMATCH = 13906;
    PARTNERDISABLEDTO = 13907;
    OPERATORDENY = 13908;
    NVRAMSIZEMISMATCH = 13909;
    VERSIONMISMATCH = 13910;
    INTERCONNECTERROR = 13911;
    PARTNERBOOTING = 13912;
    SHELFHOT = 13913;
    PARTNERREVERT = 13914;
    LOCALREVERT = 13915;
    PARTNERTRYINGTAKEOVER = 13916;
    TAKEOVERINPROGRESS = 13917;
    HALTNOTAKEOVER = 13918;
    UNSYNCNVRAM = 13919;
    UNKNOWNTAKEOVERERROR = 13920;
    WAITINGFORPARTNER = 13921;
    LOWMEMORY = 13922;
    HALTING = 13923;
    MBOXUNCERTAIN = 13924;
    NOAUTOTAKEOVER = 13925;
    PARTNERNOTWAITING = 13926;
    NOAGGRS = 13927;
    NOTHINGTOTAKEOVER = 13945;
    SENDHOMEINPROGRESS = 13946;
    NVRAMDOWN = 13947;
    INTERCONNECTRESET = 13948;
    BADOPTIONS = 13949;
    NOTHALTED = 13950;
    REVERTINPROGRESS = 13951;
    SERVICEENABLED = 13952;
    INTAKEOVER = 13953;
    TOERRMAX = 13954;
    INVALIDRESERVATION = 14000;
    NODISKSFOUND = 14001;
    MUSTBEINMAINTMODE = 14002;
    FILEEXISTS = 14003;
    JUNCTIONEXISTS = 14004;
    JUNCTIONDOESNOTEXIST = 14005;
    BADFILELENGTH = 14006;
    FILER_NOT_HEALTHY = 14007;
    BADCOREID = 14100;
    COREDUMPBUSY = 14101;
    COREDUMPNOTINITIALIZED = 14102;
    SESNOTREADY = 14200;
    SESBUSY = 14201;
    RDB_HA_SF_NOT_INITIALIZED = 14300;
    RDB_HA_ID_MISMATCH = 14301;
    RDB_HA_CONFIGURED = 14302;
    RDB_HA_PARTIALLY_CONFIGURED = 14303;
    RDB_HA_NOT_CONFIGURED = 14304;
    RDB_HA_CONFIG_UUID_MISMATCH = 14305;
    RDB_HA_CANNOT_EXIT_CONFIG = 14306;
    RDB_HA_IO_ERROR = 14307;
    RDB_HA_INVALID_SLOT = 14308;
    RDB_HA_OLD_COOKIE = 14309;
    RDB_HA_INVALID_INPUT = 14310;
    RDB_HA_FAILURE = 14311;
    RDB_HA_ILLEGAL_SLOT_CONTENT = 14312;
    RDB_HA_SLOT_UUID_MISMATCH = 14313;
    FIJIINVALID = 14401;
    FIJIINVALIDEXPR = 14402;
    FIJINOFILTER = 14403;
    FIJIMAXFILTERS = 14404;
    NFS_CLIENT_STATS_NOT_ENABLED = 14424;
    SNAPVAULTERR = 14450;
}